package cn.stylefeng.guns.modular.api.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.bms.model.params.*;
import cn.stylefeng.guns.modular.bms.model.result.BmsIndustryResult;
import cn.stylefeng.guns.modular.bms.model.result.BmsPostInfoResult;
import cn.stylefeng.guns.modular.bms.model.result.BmsWelfareResult;
import cn.stylefeng.guns.modular.bms.model.result.CityResult;
import cn.stylefeng.guns.modular.bms.service.*;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/api/bms")
@Api(tags = "基础信息管理类")
@CrossOrigin
public class ApiBmsController extends BaseController {

    @Resource
    private BmsIndustryService industryService;
    @Resource
    private BmsPostInfoService postInfoService;
    @Resource
    private BmsWelfareService welfareService;
    @Resource
    private CityService cityService;
    @Resource
    private SchoolService schoolService;

    /**
     * 查询行业信息列表
     */
    @ResponseBody
    @RequestMapping(value = "/getIndustryList",method = RequestMethod.GET)
    @ApiOperation(value = "查询行业信息列表", notes = "查询行业信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pid", value = "父类ID", required = false, paramType = "query")
    })
    public ResponseData getIndustryList(Long pid) {
        BmsIndustryParam vipParam=new BmsIndustryParam();
        List<BmsIndustryResult> list;
        if (pid!=null){
            vipParam.setPid(pid);
            list= industryService.findListBySpec(vipParam);
        }else{
            //查询父类
            vipParam.setPid(0L);
            list= industryService.findListBySpec(vipParam);
            //查询之类
            for (int i=0;i<list.size();i++){
                vipParam.setPid(list.get(i).getId());
                list.get(i).setChild( industryService.findListBySpec(vipParam));
            }
        }
        return ResponseData.success(list);
    }


    /**
     * 查询职位信息列表
     */
    @ResponseBody
    @RequestMapping(value = "/getPostList",method = RequestMethod.GET)
    @ApiOperation(value = "查询职位信息列表", notes = "查询职位信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pid", value = "父类ID", required = false, paramType = "query")
    })
    public ResponseData getPostList(Long pid) {
        BmsPostInfoParam vipParam=new BmsPostInfoParam();
        List<BmsPostInfoResult> list;
        List<BmsPostInfoResult> child;
        if (pid!=null){
            vipParam.setPid(pid);
            list= postInfoService.findListBySpec(vipParam);
        }else{
            //查询父类
            vipParam.setPid(0L);
            list= postInfoService.findListBySpec(vipParam);
            //查询之类
            for (int i=0;i<list.size();i++){
                vipParam.setPid(list.get(i).getId());
                child=postInfoService.findListBySpec(vipParam);
                for (int j=0;j<child.size();j++){
                    vipParam.setPid(child.get(j).getId());
                    child.get(j).setChild(postInfoService.findListBySpec(vipParam));
                }
                list.get(i).setChild(child);
            }
        }
        return ResponseData.success(list);
    }


    /**
     * 查询职位列表
     */
    @ResponseBody
    @RequestMapping(value = "/getHotPostList",method = RequestMethod.GET)
    @ApiOperation(value = "查询职位列表", notes = "查询职位列表")
    public ResponseData getHotPostList(BmsPostInfoParam param) {
        param.setHot(1);
        List<BmsPostInfoResult> list= postInfoService.findListBySpec(param);
        return ResponseData.success(list);
    }


    /**
     * 查询职位列表
     */
    @ResponseBody
    @RequestMapping(value = "/getPostPageList",method = RequestMethod.GET)
    @ApiOperation(value = "查询职位列表", notes = "查询职位列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "每页数量", dataType = "Integer", paramType = "query")
    })
    public ResponseData getPostPageList(BmsPostInfoParam param) {
        LayuiPageInfo pageInfo= postInfoService.findPageBySpec(param);
        return ResponseData.success(pageInfo);
    }


    /**
     * 查询福利信息表
     */
    @ResponseBody
    @RequestMapping(value = "/getWelfareList",method = RequestMethod.GET)
    @ApiOperation(value = "查询福利信息表", notes = "查询福利信息表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pid", value = "父类ID", required = false, paramType = "query")
    })
    public ResponseData getWelfareList(Long pid) {
        BmsWelfareParam vipParam=new BmsWelfareParam();
        List<BmsWelfareResult> list;
        if (pid!=null){
            vipParam.setPid(pid);
            list= welfareService.findListBySpec(vipParam);
        }else{
            //查询父类
            vipParam.setPid(0L);
            list= welfareService.findListBySpec(vipParam);
            //查询之类
            for (int i=0;i<list.size();i++){
                vipParam.setPid(list.get(i).getId());
                list.get(i).setChild( welfareService.findListBySpec(vipParam));
            }
        }
        return ResponseData.success(list);
    }

    /**
     * 查询所有城市列表
     */
    @ResponseBody
    @RequestMapping(value = "/getCityList",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有城市列表", notes = "查询所有城市列表")
    public ResponseData getCityList() {
        CityParam cityParam=new CityParam();
        Map<String,Object> result;
        result= cityService.findListForApp(cityParam);
        return ResponseData.success(result);
    }

    /**
     * 查询所有城市列表
     */
    @ResponseBody
    @RequestMapping(value = "/getHotCityList",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有城市列表", notes = "查询所有城市列表")
    public ResponseData getHotCityList() {
        List<CityResult> result= cityService.findListBySpec(new CityParam().setIsHot(1));
        return ResponseData.success(result);
    }

    /**
     * 查询学校列表
     */
    @ResponseBody
    @RequestMapping(value = "/getSchoolList",method = RequestMethod.GET)
    @ApiOperation(value = "查询学校列表", notes = "查询学校列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "每页数量", dataType = "Integer", paramType = "query")
    })
    public ResponseData getSchoolList(SchoolParam param) {
        LayuiPageInfo pageInfo= schoolService.findPageBySpec(param);
        return ResponseData.success(pageInfo);
    }

}